import com.sun.jna.platform.win32.WinDef;
import org.zjx.resolution.resolution.StartWindowResolution;
import org.zjx.resource.Config_800_600;
import org.zjx.resource.ResourceManager;
import org.zjx.util.HwndUtil;
import org.zjx.util.ImageUtil;
import org.zjx.window.GameWindow;

import java.awt.*;
import java.awt.image.BufferedImage;

public class ScreenText {

    public static WinDef.HWND getWindowHwnd(String className, String titleName) {
        return HwndUtil.getHwnd(className, titleName);
    }

    public static void main(String[] args) {
        ResourceManager.CONFIG = new Config_800_600();
        loadWindow();

//        Map<String,Object> map = new HashMap<>();
//        map.put("你好啊","fawfaew");
//        map.put("aerg",3);
//        map.put("ergwerg",new Rect(15,54,15,4));
//
//        String ss = JSON.toJSONString(map);
//        System.out.println(ss);
    }


    public static void startWindowTest(){
        StartWindowResolution resolution = new StartWindowResolution();

        // 尝试加载配置
        if (!resolution.loadResolution()) {
            // 加载失败，使用默认值
            System.out.println("使用默认启动窗口配置");

            // 可选：保存默认配置
            resolution.saveDefaultConfiguration();
        }
    }

    public static void loadWindow(){
        StartWindowResolution resolution = new StartWindowResolution();
        resolution.loadResolution();

        WinDef.HWND hwnd = getWindowHwnd((String) resolution.getProperties().get(StartWindowResolution.START_WINDOW_CLASS_NAME), (String) resolution.getProperties().get(StartWindowResolution.START_WINDOW_TITLE_NAME));

        GameWindow gameWindow = new GameWindow(new Point(0,0));
        gameWindow.init(hwnd,GameWindow.WINDOW_STATUS_START);
        gameWindow.move(new Point(0,0));

        BufferedImage image = gameWindow.getImage(resolution.getButton(StartWindowResolution.START_WINDOW_START_BUTTON_RECT).getRect());

        BufferedImage button = ImageUtil.stringToBufferedImage(resolution.getButton(StartWindowResolution.START_WINDOW_START_BUTTON_RECT).getPattern());

        boolean same = ImageUtil.areImagesEqual(image, button);

        System.out.println(ImageUtil.bufferedImageToString(image));
    }

}
